package ysq.xyg.recovery.controller;

import cn.hutool.core.util.StrUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.recovery.model.po.RecoveryCircle;
import ysq.xyg.recovery.model.vo.RecoveryCircleVo;
import ysq.xyg.recovery.service.RecoveryCircleService;
import ysq.xyg.web.model.po.WebAddress;
import ysq.xyg.web.service.WebAddressService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 回收金模块-回收商圈controller层
 *
 * @author congcong tao
 * @date 2019-8-1 15:02:22
 */
@RestController
public class RecoveryCircleController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(RecoveryCircleController.class);

    @Autowired
    private WebAddressService webAddressService;
    @Resource
    private RecoveryCircleService recoveryCircleService;

    private RecoveryCircle recoveryCircle;

    /**
     * 分页查询
     *
     * @param recoveryCircleVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author congcong tao
     * @date 2019-8-1 15:02:22
     */
    @BaseLog(module = "回收金模块",className = "回收商圈",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryCircle/page",method = RequestMethod.POST)
    public ReturnEntity page(RecoveryCircleVo recoveryCircleVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = recoveryCircleService.pageLeft(recoveryCircleVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-8-1 15:02:22
     */
    @RequestMapping(value = "/recoveryCircle/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/recovery/recoveryCircleUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            recoveryCircle = recoveryCircleService.selectByPrimaryKey(id);
            String area = recoveryCircle.getArea();
            WebAddress webAddress = webAddressService.selectByPrimaryKey(area);
            recoveryCircle.setAreaName(webAddress.getArea());
            String image = recoveryCircle.getImage();
            if (StringUtils.isNotEmpty(image)) {
                view.addObject("imageArr", image.split(","));
            }
            view.addObject("recoveryCircle", recoveryCircle);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-8-1 15:02:22
     */
    @BaseLog(module = "回收金模块",className = "回收商圈",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryCircle/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return recoveryCircleService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param recoveryCircleVo Vo对象
     * @author congcong tao
     * @date 2019-8-1 15:02:22
     */
    @BaseLog(module = "回收金模块",className = "回收商圈",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryCircle/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity addOrUpdate(HttpServletRequest request, RecoveryCircleVo recoveryCircleVo){
        return recoveryCircleService.addOrUpdate(recoveryCircleVo,acceptCurrentUser(request));
    }

    /**
     * 根据ids更改状态
     * @param ids ids用逗号区分
     * @param status
     * @param manageContent
     * @author congcong tao
     * @date 2019/8/2 16:11
     */
    @RequestMapping(value = "/recoveryCircle/updateStatus")
    public ReturnEntity updateStatus(String ids, String status, String manageContent){
        return recoveryCircleService.updateStatus(ids, status, manageContent);
    }
}